#include "AdContent.h"

bool ActivityContent::insertAdContent(Mat& newAdImage, long long adId){
	if (ads.find(adId) != ads.end()){
		cout << "Conflict Ad Id: pelease change" << endl;
		return false;
	}
	if (newAdImage.rows % 8 != 0 || newAdImage.cols % 8 != 0){
		cout << "Only process image 8N*8M" << endl;
		return false;
	}

	

	AdContent* newAd = new AdContent(newAdImage);
	pair<unordered_map<long long, AdContent*>::iterator, bool> mypair = ads.insert(make_pair(adId, newAd));
	if (!mypair.second){
		cout << "new ad content insert failed" << endl;
		return false;

	}
	else{
		cout << " Ad :" << adId << "insert successfully! " << endl;
		return true;
	}

}

bool ActivityContent::deleteAdContent(long long adId){
	unordered_map<long long, AdContent*>::iterator it = ads.find(adId);
	if (it == ads.end()){
		cout << "no such ad: " << adId << endl;
		return false;
	}
	else{
		ads.erase(it);
		cout << "successfully delete ad content: " << adId << endl;
		return true;
	}
}

pair<AdContent*, bool> ActivityContent::searchAdContent(long long adId){
	unordered_map<long long, AdContent*>::iterator it = ads.find(adId);
	if (it == ads.end()){
		cout << "no such ad content in our database, adId:" << adId << endl;
		return make_pair(it->second, false);
	}
	else{
		return make_pair(it->second, true);
	}
}
